
<title>课程设置</title>

<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a><cite>设置</cite></a>
        <a><cite>课程设置</cite></a>
    </div>
</div>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">课程设置</div>
                <div class="layui-card-body">
                    <div class="layui-form" lay-filter="lessonDateConfig">
                    <div class="layui-form-item">
                        <label class="layui-form-label" style="width: 28px; margin-left: 0px;">学年</label>
                        <div class="layui-input-inline" style="width: 92px; float: left; margin-left: 10px;">
                            <input type="text" id="year" name="year" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label" style="width: 28px; margin-left: 0px; ">学期</label>
                        <div class="layui-input-inline" style="width: 92px; float: left; margin-left: 10px;">
                            <select id="semester" name="semester">
                                <option value="0">0</option>
                                <option value="1">1</option>
                                <option value="2">2</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form">
                        <div class="layui-form-item">
                            <label class="layui-form-label" style="width: 28px; margin-left: 0px;">起始日期</label>
                            <div class="layui-input-inline" style="width: 92px; float: left; margin-left: 10px;">
                                <input type="text" id="startTime" name="startTime" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block" style="float: left; margin-left: 66px;">
                                <button class="layui-btn" lay-submit lay-filter="setSpiderConfig">确认修改</button>
                            </div>
                        </div>
                    </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

<script>
    Date.prototype.Format = function (fmt) { //author: meizz
        var o = {
            "M+": this.getMonth() + 1, //月份
            "d+": this.getDate(), //日
            "h+": this.getHours(), //小时
            "m+": this.getMinutes(), //分
            "s+": this.getSeconds(), //秒
            "q+": Math.floor((this.getMonth() + 3) / 3), //季度
            "S": this.getMilliseconds() //毫秒
        };
        if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    };

    layui.use(['form','laydate'], function () {
        var form = layui.form,
            $ = layui.$, laydate = layui.laydate;
        var configUrl = "/admin/config";
        var setConfigUrl = "/admin/config/lesson/date";
        $.ajax({
            url:        configUrl,
            dataType:   'json',
            type:       'GET',
            complete    :function (result) {
                var data = result.responseJSON;
                var status = data.status;
                if (status !== 200){
                    layer.msg("请求配置数据失败！")
                    return;
                }
                data = data.data;
                var startDateArr = data.lessonConfig.startDate;
                var date = new Date(startDateArr[0], startDateArr[1] - 1, startDateArr[2]).Format("yyyy-MM-dd");
                laydate.render({
                    elem: '#startTime'
                    ,value: date
                });
                laydate.render({
                    elem: "#year"
                    ,value: data.lessonConfig.year
                    ,type: 'year'
                });
                form.val("lessonDateConfig", {
                    semester: data.lessonConfig.semester
                });
                form.render();
            }
        });
        form.on('submit(setSpiderConfig)', function (data) {
            layer.confirm("确认修改", function (index) {
                var load = layer.load(2);
                $.ajax({
                    url: setConfigUrl,
                    dataType:   'json',
                    type:       'POST',
                    data:       data.field,
                    complete:   function (result) {
                        layer.close(load);
                        result = result.responseJSON;
                        var status = result.status;
                        if (status == 200) {
                            layer.msg("修改成功");
                        }else{
                            layer.msg("修改失败");
                        }
                    }
                });
                layer.close(index);
            })

        });
    });
</script>